package mk.edu.ii.navigatemacedonia;

import java.io.Serializable;

public class Site implements Serializable  {
	static private final long serialVersionUID = 42L;
	
	 private String siteID;
	 private String siteName;
	 private String siteDescription;
	 private String siteCategory;
	 private String siteSubCategory;
	 private Float  siteRating;
	 private String siteImage;
	 private Double siteLongitude;
	 private Double siteLatitude;
	 private Float  siteDistance;
	 private Float  siteBearing;
	 
	 
	 
	 public Site(String siteID, String siteName, String siteDescription, String siteCategory
			 , String siteImage, String siteLongitude, String siteLatitude
			 , String siteSubCategory, String siteRating)
	 {
		 
		 this.siteName = siteName;
		 this.siteCategory = siteCategory;
		 this.siteDescription = siteDescription;
		 this.siteImage = siteImage;
		 this.siteSubCategory = siteSubCategory;
		 this.siteID = siteID;
		 
		 try{
			 this.siteLatitude = Double.parseDouble(siteLatitude);
			 }
		 catch(NumberFormatException e){
			 this.siteLatitude = -1d;
			 }
		
		 try{
			 this.siteLongitude = Double.parseDouble(siteLongitude);
			 }
		 catch(NumberFormatException e){
			 this.siteLongitude = -1d;
			 }
		
		 try{
			 this.siteRating = Float.parseFloat(siteRating);
		 }
		 catch(NumberFormatException e){
			 this.siteRating = -1f;
		 }
	 };
	 
	 public void setSiteDistance(Float distance){
		 this.siteDistance=distance;
	 }
	 
	 public void setSiteBearing(Float bearing){
		 this.siteBearing=bearing;
	 }
	 
	 public String getSiteName(){
		 return this.siteName;
	 }
	 
	 public String getSiteDescription(){
		 return this.siteDescription;
	 }
	 
	 public String getSiteCategory(){
		 return this.siteCategory;
	 }
	 
	 public String getSiteImage(){
		 return this.siteImage;
	 }
	 
	 public Double getSiteLatitude(){
		 return this.siteLatitude;
	 }
	 
	 public Double getSiteLongitude(){
		 return this.siteLongitude;
	 }
	 
	 public Float getSiteRating(){
		 return this.siteRating;
	 }
	 
	 public String getSubCategory(){
		 return this.siteSubCategory;
	 }
	 
	 public String getSiteID(){
		 return siteID;
	 }
	 
	 public String getSiteDistance(){
		 
		 String d;
		 if(this.siteDistance<1000)
			{
				d=String.valueOf(this.siteDistance.intValue())+"m";
			}
			else{
				if(this.siteDistance>500000){
					d=">500km";
				}else{
				d=String.valueOf(this.siteDistance/1000);
				d=d.substring(0, d.indexOf(".")+2)+"km";
				}
			}
		 return d;
	 }
	 public Float getSiteDistanceF(){
		 return this.siteDistance;
	 }
	 
	 public Float getSiteBearing(){
		 return this.siteBearing;
	 }
	 
	 static String getBearingString(float angle){
			if(angle >= -22 && angle < 22)
				return "N";
			if(angle >= 22  && angle < 67)
				return "NE";
			if(angle >= 67  && angle < 112)
				return "E";
			if(angle >= 112  && angle < 157)
				return "SE";
			if(angle >= -157 && angle <-112)
				return "SW";
			if(angle >= -112 && angle < - 67)
				return "W";
			if(angle >= -67 && angle < -22)
				return "NW";
			else
				return "S";
		}
	 
}
